package entity;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "invitation")
@NamedQueries({
    @NamedQuery(name = "Invitation.findAll", query = "SELECT i FROM Invitation i"),
    @NamedQuery(name = "Invitation.findByEventId", query = "SELECT i FROM Invitation i WHERE i.invitationPK.eventId = :eventId"),
    @NamedQuery(name = "Invitation.findBySenderUsername", query = "SELECT i FROM Invitation i WHERE i.invitationPK.senderUsername = :senderUsername"),
    @NamedQuery(name = "Invitation.findByReceiverUsername", query = "SELECT i FROM Invitation i WHERE i.invitationPK.receiverUsername = :receiverUsername"),
    @NamedQuery(name = "Invitation.findByTitle", query = "SELECT i FROM Invitation i WHERE i.title = :title")})
public class Invitation implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId
    protected InvitationPK invitationPK;
    
    @Basic(optional = false)
    @Size(min = 1, max = 45)
    @Column(name = "title")
    private String title;
    
    @Basic(optional = false)
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "text")
    private String text;
    
    @JoinColumn(name = "eventId", referencedColumnName = "eventId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Event event;
    
    @JoinColumn(name = "senderUsername", referencedColumnName = "username", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User sender;
    
    @JoinColumn(name = "receiverUsername", referencedColumnName = "username", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User receiver;

    public Invitation() {
    }

    public Invitation(InvitationPK invitationPK) {
        this.invitationPK = invitationPK;
    }

    public Invitation(InvitationPK invitationPK, String title, String text) {
        this.invitationPK = invitationPK;
        this.title = title;
        this.text = text;
    }

    public Invitation(int eventId, String senderUsername, String receiverUsername) {
        this.invitationPK = new InvitationPK(eventId, senderUsername, receiverUsername);
    }

    public InvitationPK getInvitationPK() {
        return invitationPK;
    }

    public void setInvitationPK(InvitationPK invitationPK) {
        this.invitationPK = invitationPK;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public User getSender() {
        return sender;
    }

    public void setSender(User sender) {
        this.sender = sender;
    }

    public User getReceiver() {
        return receiver;
    }

    public void setReceiver(User receiver) {
        this.receiver = receiver;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (invitationPK != null ? invitationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Invitation)) {
            return false;
        }
        Invitation other = (Invitation) object;
        return Objects.equals(this.invitationPK, other.invitationPK);
    }

    @Override
    public String toString() {
        return "entity.Invitation[ invitationPK=" + invitationPK + " ]";
    }
    
}
